package cn.yxl.org.service.impl;

import cn.yxl.basic.utils.PageList;
import cn.yxl.org.domain.Department;
import cn.yxl.org.mapper.DepartmentMapper;
import cn.yxl.org.query.DepartmentQuery;
import cn.yxl.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {


    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public List<Department> queryAll() {
        return departmentMapper.selectAll();
    }

    @Override
    public Department queryById(Long id) {
        return departmentMapper.selectById(id);
    }

    @Override
    @Transactional
    public void save(Department department) {
       departmentMapper.save(department);
    }

    @Override
    @Transactional
    public void update(Department department) {
       departmentMapper.update(department);
    }

    @Override
    @Transactional
    public void delete(Long id) {
          departmentMapper.delete(id);
    }

    @Override
    public PageList<Department> queryByPage(DepartmentQuery query) {
        PageList<Department> pageList = new PageList<>();
        //查询当前页数据
        List<Department> rows = departmentMapper.selectByPage(query);
        pageList.setRows(rows);
        //统计条数
        Long total = departmentMapper.count(query);
        pageList.setTotal(total);
        return pageList;
    }
}
